import {
    VALIDATE,
    TO_LOGIN_PHONE,
    TO_LOGIN_PWD,
    TO_LOGOUT,
    SEND_SMS,
    GET_IMAGE_CAPTCHA,
    UPLOAD_FILE_OSS,
    QUERY_LOGIN_QRCODE,
    QUERY_LOGIN_QRCODE_STATUS,
    QUERY_OPENID,
    TO_LOGIN_OPENID,
    REFRESH_TOKEN_URL,
    BIND_PHONE,
} from '@/config/url';
import request from '@/utils/request';

// 校验一个用户是否登录
export const validate = () => {
    return Promise.resolve({code: OK_CODE, data: {}, message: 'success'});
    return request(VALIDATE);
};

// 手机验证码登录
export const login = (data={}) => {
    return request(TO_LOGIN_PHONE, {method: 'post', data, contentType: 'multipart/form-data'});
};

// 账号密码登录
export const loginPwd = (data={}) => {
    return request(TO_LOGIN_PWD, {method: 'post', data});
};

// 公众号openId登录
export const loginOpenId = (data) => {
    return request(TO_LOGIN_OPENID, {data});
};
// code换区openId
export const getWxOpenId = (data) => {
    return request(QUERY_OPENID, {data});
};

// 退出登录
export const logout = () => {
    return request(TO_LOGOUT);
};

// 获取图形验证码
export const getImageCaptcha = data => {
    return request(GET_IMAGE_CAPTCHA, {data});
};

// 发送验证码
export const sendSms = (data={}) => {
    return request(SEND_SMS, {method: 'post', data});
};

// 获取微信二维码
export const queryQrCode = (data) => {
    return request(QUERY_LOGIN_QRCODE, {data});
};

// 查询二维码扫描状态
export const queryQrStatus = (data) => {
    return request(QUERY_LOGIN_QRCODE_STATUS, {data});
};
// 查询二维码扫描状态(绑定微信)
export const queryQrBindStatus = (data) => {
    return request('QUERY_LOGIN_QRCODE_STATUS_BIND', {method: 'post', data, contentType: 'multipart/form-data'});
};
// 绑定手机
export const toBindPhone = (data) => {
    return request(BIND_PHONE, {method: 'post', data, contentType: 'multipart/form-data'});
};


// 上传图片
export const uploadImage = (data, onUploadProgress) => {
    let obj = {};
    if(onUploadProgress && 'function' === typeof onUploadProgress) obj['onUploadProgress'] = onUploadProgress;
    return request(UPLOAD_FILE_OSS, {method: 'post', data, contentType: 'multipart/form-data', ...obj});
}

// 刷新token
export const refreshToken = (data={}) => {
    return request(REFRESH_TOKEN_URL, {data});
};


